<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="../js/jquery-3.5.1.min.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>
		<input type="text" class="p1" /><br />
		<input type="button" class="b1" value="求和" />
		<script type="text/javascript">
			$(function() {
				$(".b1").click(function() {
					var nums = $(".p1").val();
					var num = nums.match(/\d+/ig);
					var sum = 0;
					for(var i = 0;i < num.length;i++){
						num[i] = parseInt(num[i],10);
						sum += num[i];
					}
					alert(sum);
				})
			})
		</script>

	</body>
</html>
